<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
            思路:
                //获取一个随机数    Math.random();
                //将这个随机数的范围扩大(20+1)
                //对这个随机数向下取整
        */
        function fn() {
            //获取一个随机数
            var ran = Math.random();
            //将ran这个随机数扩大21倍
            var res = ran*(20+1)
            //对res进行向下取整
            return Math.floor(res)
        }

        console.log(fn());
    </script>
</body>

</html>